<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="../../top.jsp"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
		<div>
			<table style="width:400px;">
			<input type="hidden" value="${mac.flag}" name="flag" id="flag">
			<input type="hidden" value="${mac.MAC_ADDR_CODE}"  id="macCode">
			<tr>
				<td style="width: 20%;text-align: right;"><span
					style="color: red;">*</span>Mac地址:</td>
				<td style="width: 80%;text-align: left;"><input type="text" name="mac_addr_code" id="mac_addr_code" onblur="hasCode();" style="margin-top: 10px;"></td>
			</tr>
			<tr>
				<td style="width: 20%;text-align: right;"><span
					style="color: red;">*</span>状态:</td>
				<td style="width: 80%;text-align: left;">
				<label class="label-style"><input type="radio" class="singleInput" name="status" id="status1" value="0" checked><span class="lbl">启用</span></label>
				<label class="label-style"><input type="radio" class="singleInput" name="status" id="status2" value="1"><span class="lbl">停用</span></label>
				</td>
			</tr>
			</table>
				<div style="width: 400px;text-align: center;margin-top: 100px;">
				<a	class="btn btn-mini btn-primary" onclick="save();">保存</a> 
				<a	class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					</div>
		</div>
</body>


<script type="text/javascript">
$(function(){
	top.hangge();
	
	
});
var rootPath = getRootPath();
var saveFlag =true;
var mac_addr_code = '${mac.MAC_ADDR_CODE}';
var macCode =$("#macCode").val();//编辑判断 //update条件
var status ='${mac.STATUS}';
$("#mac_addr_code").val(mac_addr_code);
$("input[name='radioName'][value="+status+"]").attr("checked",true);




function save(){
	if($("#mac_addr_code").val()==""){
		
		$("#mac_addr_code").tips({
			side:3,
            msg:'mac地址不能为空',
            bg:'#AE81FF',
            time:2
        });
		$("#mac_addr_code").focus();
		return false;
	}
	//mac地址是否存在
	hasCode();
	
	if(saveFlag==false){
		return;
	}
	saveFlag=false;
	
	top.jzts();
	var param ={};
	param['mac_addr_code'] =$("#mac_addr_code").val();
	param['status'] =$("input[name='status']:checked").val();
	param['flag'] =$("#flag").val();
	param['oldMacCode'] =macCode;
	var url =rootPath+'/mac/saveMac.do?tm='+ new Date().getTime();
	$.post(url,param,function(callback){
		top.hangge();
		if(callback.isSuccess=='true'){
			bootbox.dialog("保存成功!", [ {
				"label" : "关闭",
				"class" : "btn-small btn-success",
				"callback" : function() {
					top.Dialog.close();
				}
			} ]);
		}else{
			saveFlag=true;
			bootbox.alert("保存失败");
			top.Dialog.close();
			
		}
		
		
	});
}

//mac地址是否存在
function hasCode(){
	
		var mac_addr_code = $.trim($("#mac_addr_code").val());
		$.ajax({
			type: "POST",
			url: '<%=basePath%>mac/hasCode.do',
	    	data: {mac_addr_code : mac_addr_code},
			cache: false,
			async:false,
			success: function(data){
				 if("ok" == data.msg){
					 $("#mac_addr_code").tips({
							side:3,
				            msg:'此mac地址已存在',
				            bg:'#AE81FF',
				            time:1
				        });
						saveFlag=false;
				 }else if("error" == data.msg){
					 bootbox.alert("出错了!");
					 saveFlag=false;
				 }else{
					 saveFlag=true;
				 }
			}
		});

}


function getRootPath() {
	// 获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
	var curWwwPath = window.document.location.href;
	// 获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	// 获取主机地址，如： http://localhost:8083
	var localhostPaht = curWwwPath.substring(0, pos);
	// 获取带"/"的项目名，如：/uimcardprj
	var projectName = pathName.substring(0,
			pathName.substring(1).indexOf('/') + 1);
	return (localhostPaht + projectName);
}
</script>
</html>